package com.zeng.configuration.microprofile.config.source;

import org.eclipse.microprofile.config.spi.ConfigSource;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @author zyb
 * @date 2021-03-14 14:33
 */
public class ClasspathAppPropertiesConfigSource extends MapBasedConfigSource {
    private static final String CONFIG_FILE_LOCATION = "app.properties";

    public ClasspathAppPropertiesConfigSource() {
        super("classpath:app.properties", 1);
    }

    @Override
    protected Map<String, String> prepareConfigData() throws Throwable {
        ClassLoader classLoader = ClasspathAppPropertiesConfigSource.class.getClassLoader();
        InputStream inputStream = classLoader.getResourceAsStream(CONFIG_FILE_LOCATION);
        Properties properties = new Properties();
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new HashMap(properties);
    }
}
